package cn.lizemin.service;

import cn.lizemin.entity.User;
import cn.lizemin.mapper.UserDao;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lzm
 * @version 1.0
 * @description: TODO
 * @date 2021/12/26 18:04
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class UserServiceImpl implements UserService {

    private UserDao userDao;

    private static final Logger LOGGER = LoggerFactory.getLogger(UserServiceImpl.class);


    @Autowired
    public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public void save(User user) {
        LOGGER.info("姓名:{}",user.getName());
        LOGGER.info("姓名:{}==>{}==>{}",user.getName(),user.getBirthday(),user.getSalary());
        LOGGER.info("生日:{}",user.getBirthday().toString());
        LOGGER.info("工资:{}",user.getSalary().toString());
        userDao.save(user);
        //如果事务生效，这条记录是不会插入到数据库中的
//        int i = 5 / 0;
    }


}
